package com.matt.system.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.matt.system.domain.TSysuser;
import com.matt.system.service.UserService;
import com.opensymphony.xwork2.ActionSupport;
@Controller
public class LoginAction extends ActionSupport {
	
	/**
	 * 用户登录
	 * create by MATT
	 */
	
	private static final long serialVersionUID = 1L;

	private String userName;
	
	private String password;
	
	private HttpServletRequest request;
	
	private HttpServletResponse response;
	
	@Autowired
	private UserService userService;

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	@Override
	public String execute() throws Exception {
		request = ServletActionContext.getRequest();
		response = ServletActionContext.getResponse();
		response.setContentType("text/html; charset=UTF-8");
		HttpSession session=request.getSession();
		TSysuser user = userService.login(userName, password);
		
		if(user != null){
			session.setAttribute("user", user);
			response.getWriter().write("true");
			return null;
		}
		return null;
	}
	
}
